﻿<?php
	session_start();
	//session_destroy();
?>
<html>
	<head>
		<title>Dang nhap</title>
	</head>
	<body>
		
		<?php
			if(isset($_SESSION["Dangnhap"]))
			{
				echo("co session");
				//Header("Location: DangNhapThanhCong.php");
			}
			else
			{
				if(!isset($_REQUEST["txtTenDangNhap"]) || !isset($_REQUEST["txtMatKhau"]))
				{	
					$tendangnhap = "";
					$matkhau = "";
				}
				else
				{
					$tendangnhap = $_REQUEST["txtTenDangNhap"];
					$matkhau = $_REQUEST["txtMatKhau"];
					$connection = mysql_connect("localhost","root","12345") or ("couldn't connect to localhost");
					mysql_select_db("dangnhap",$connection);
					mysql_query("set names 'utf8'");
					$sql = "select count(*) as nums from DangNhap where TenDangNhap = '".$tendangnhap."' and MatKhau = '".$matkhau."'";
					$result = mysql_query($sql, $connection);
					
					echo $sql;
					mysql_close($connection);
					
					$row =  mysql_fetch_array($result);
					$numrow = $row['nums'];
					if($numrow > 0)
					{
						//$arr = array($tendangnhap, $matkhau);
						$_SESSION["Dangnhap"] = $tendangnhap;
						$ketquadangnhap = true;
						Header("Location: DangNhapThanhCong.php");
						echo ("Xin chao ". $tendangnhap);
					}
				}
			}
			?>		
			<form name="formDangNhap" method="post" action="DangNhap.php">
				<table width="400" border="0">
					 <tr> 
						<td>Tên đăng nhập</td> 
						<td> 
						  <input type="text" name="txtTenDangNhap"/> 
						</td> 
					  </tr> 
					  <tr> 
						<td>Mật khẩu</td> 
						<td> 
							<input type="password" name="txtMatKhau" /> 
						</td> 
					  </tr> 
					  <tr> 
						<td align="right"> <input type="submit" name="btnDangNhap" value="Đăng nhập" /></td> 
						<td> <input type="reset" name="btnLamLai" value="Làm lại" /></td> 
					  </tr> 
					  <tr>
						<td> <input type="checkbox" name="chkboxLuu" value="Luu mat khau" />Luu mat khau</td>
					  </tr>
				</table>
			</form>
			
			<a href="Logout.php">Log out</a>
			<a href="DangKy.php">Dang ky</a>
			
			
	</body>
</html>
